package com.free.front.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功能概述:
 * </p>
 * <p>
 * 功能详述:
 * </p>
 */
public class ChangeUtil {
    /*========================================================================*
     *                         Public Fields (公共属性)
     *========================================================================*/

    /*========================================================================*
     *                         Private Fields (私有属性)
     *========================================================================*/

    /*========================================================================*
     *                         Construct Methods (构造方法)
     *========================================================================*/

    /*========================================================================*
     *                         Public Methods (公有方法)
     *========================================================================*/
// 转产品描述
    public static List<Map<String, Object>> zhuanPart(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("reserve2").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("reserve2").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int a = 0;
            for (Map<String, Object> param : group) {
                a++;
                resultMap.put("reserve2", param.get("reserve2"));
                resultMap.put("reserve1", param.get("reserve1"));
                resultMap.put("reserve3", param.get("reserve3"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("产品系列".equals(param.get("PARA_NAME"))) {
                    resultMap.put("reserve4", param.get("reserve4"));
                }
            }
            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }

    // 转适用产品
    public static List<Map<String, Object>> zhuanPart2(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("PART_NUMBER").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("PART_NUMBER").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int a = 0;
            Object [] name=new Object[10];
            Object [] value=new Object[10];
            for (Map<String, Object> param : group) {
                resultMap.put("PART_NUMBER", kString(param.get("PART_NUMBER")));
                resultMap.put("PART_NAME_CN", kString(param.get("SUBLINE_NAME")));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("产品系列".equals(param.get("PARA_NAME"))) {
                    resultMap.put("prodLine", kString(param.get("PARA_VALUE")));
                } else {
                    a++;
                    name[a]=kString(param.get("PARA_NAME"));
                    value[a]=kString(param.get("PARA_VALUE"));
                }
            }

            List<String> tmp = new ArrayList<String>();
            for(Object str:name){
                if(str!=null && ((String) str).length()!=0){
                    tmp.add((String) str);
                }
            }
            List<String> tmp1 = new ArrayList<String>();
            for(Object str:value){
                if(str!=null && ((String) str).length()!=0){
                    tmp1.add((String) str);
                }
            }
            name = tmp.toArray(new String[0]);
            value = tmp1.toArray(new String[0]);
            resultMap.put("name",name);
            resultMap.put("value",value);
            //resultList.addAll(ChangeUtil.zhuan(paramsList1));
            resultList.add(resultMap);

        }
        System.out.println(resultList);
        return resultList;
    }

    // 转适用产品
    public static List<Map<String, Object>> zhuanLunTai(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("PART_NUMBER").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("PART_NUMBER").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            for (Map<String, Object> param : group) {
                resultMap.put("PART_NUMBER", param.get("PART_NUMBER"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("CRIAMI019".equals(param.get("PARA_NO"))) {
                    resultMap.put("prodLine", param.get("PARA_VALUE"));
                }
                if ("CRIAMI114".equals(param.get("PARA_NO"))) {
                    resultMap.put("value1", param.get("PARA_VALUE"));
                }
                if ("CRIAMI113".equals(param.get("PARA_NO"))) {
                    resultMap.put("value2", param.get("PARA_VALUE"));
                }
                if ("CRIAMI021".equals(param.get("PARA_NO"))) {
                    resultMap.put("value3", param.get("PARA_VALUE"));
                }

            }
            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }

    // 适用车型
    public static List<Map<String, Object>> zhuanCheXing(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("ID").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("ID").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int[] a = new int[7];
            for (Map<String, Object> param : group) {
                resultMap.put("BRAND_NAME", param.get("BRAND_NAME"));
                resultMap.put("MODEL_NAME", param.get("MODEL_NAME"));
                resultMap.put("FRAME_STRUCTURE", param.get("FRAME_STRUCTURE"));
                resultMap.put("DISPLACEMENT_L", param.get("DISPLACEMENT_L"));
                resultMap.put("ENGINE_NO", param.get("ENGINE_NO"));
                resultMap.put("POWER_KW", param.get("POWER_KW"));
                resultMap.put("START_DATE", param.get("START_DATE"));
                resultMap.put("STOP_DATE", param.get("STOP_DATE"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("CRIAMI011".equals(param.get("PARA_NO"))) {
                    a[0] = 1;
                    resultMap.put("spbz", kString(param.get("PARA_VALUE")));
                }
                if ("CRIAMI010".equals(param.get("PARA_NO"))) {
                    a[1] = 1;
                    resultMap.put("spbsxlx", kString(param.get("PARA_VALUE")));
                }
                if ("CRIAMI009".equals(param.get("PARA_NO"))) {
                    a[2] = 1;
                    resultMap.put("syfdjxh", kString(param.get("PARA_VALUE")));
                }
                if ("AMI203".equals(param.get("PARA_NO"))) {
                    a[3] = 1;
                    resultMap.put("spscpbz", kString(param.get("PARA_VALUE")));
                }
                if ("21".equals(param.get("PARA_NO"))) {
                    a[4] = 1;
                    resultMap.put("pjsycxqsnf",kString(param.get("PARA_VALUE")));
                }
                if ("20".equals(param.get("PARA_NO"))) {
                    a[5] = 1;
                    resultMap.put("pjsycxjznf",kString(param.get("PARA_VALUE")));
                }
                if ("100B".equals(param.get("PARA_NO"))) {
                    a[6] = 1;
                    resultMap.put("azwz", kString(param.get("PARA_VALUE")));
                }
                kMap(a, param, resultMap, 1, "");
            }

            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }
    public static List<Map<String, Object>> zhuanMdCheXing(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("ID").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("ID").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int[] a = new int[7];
            for (Map<String, Object> param : group) {
                resultMap.put("BRAND_NAME", param.get("BRAND_NAME"));
                resultMap.put("MODEL_NAME", param.get("MODEL_NAME"));
                resultMap.put("FRAME_STRUCTURE", param.get("FRAME_STRUCTURE"));
                resultMap.put("DISPLACEMENT_L", param.get("DISPLACEMENT_L"));
                resultMap.put("ENGINE_NO", param.get("ENGINE_NO"));
                resultMap.put("POWER_KW", param.get("POWER_KW"));
                resultMap.put("START_DATE", param.get("START_DATE"));
                resultMap.put("STOP_DATE", param.get("STOP_DATE"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("CRIAMI011".equals(param.get("PARA_NO"))) {
                    a[0] = 1;
                    resultMap.put("spbz", kString(param.get("PARA_VALUE")));
                }
                if ("CRIAMI010".equals(param.get("PARA_NO"))) {
                    a[1] = 1;
                    resultMap.put("spbsxlx", kString(param.get("PARA_VALUE")));
                }
                if ("CRIAMI009".equals(param.get("PARA_NO"))) {
                    a[2] = 1;
                    resultMap.put("syfdjxh", kString(param.get("PARA_VALUE")));
                }
                if ("AMI203".equals(param.get("PARA_NO"))) {
                    a[3] = 1;
                    resultMap.put("spscpbz", kString(param.get("PARA_VALUE")));
                }
                if ("21".equals(param.get("PARA_NO"))) {
                    a[4] = 1;
                    resultMap.put("pjsycxqsnf",(String)kString(param.get("PARA_VALUE")));
                }
                if ("20".equals(param.get("PARA_NO"))) {
                    a[5] = 1;
                    resultMap.put("pjsycxjznf",kString(param.get("PARA_VALUE")));
                }
                if ("100B".equals(param.get("PARA_NO"))) {
                    a[6] = 1;
                    resultMap.put("azwz", kString(param.get("PARA_VALUE")));
                }
                //kMap(a, param, resultMap, 1, "");
            }

            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }

    public static Object kString(Object object) {
        Object string2 = "";
        string2 = object;
        if ("".equals(string2)||string2==null) {
            string2 = " ";
        }
        return string2;
    }

    public static List<Map<String, Object>> zhuan(List<Map<String, Object>> paramsList1) {
        List<Map<String, Object>> resultList1 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("PART_NUMBER").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("PART_NUMBER").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int a = 0;

            for (Map<String, Object> param : group) {

                resultMap.put("PART_NUMBER", param.get("PART_NUMBER"));
                resultMap.put("PART_NAME_CN", param.get("SUBLINE_NAME"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                if ("产品系列".equals(param.get("PARA_NAME"))) {
                    resultMap.put("prodLine", param.get("PARA_VALUE"));
                } else {
                    a++;
                    resultMap.put("name" + a + "", param.get("PARA_NAME"));
                    resultMap.put("value" + a + "", param.get("PARA_VALUE"));
                }
            }
            resultList.add(resultMap);
            List<List<String>> lis=new ArrayList<List<String>>();
            Map<String, Object> param=new HashMap<String, Object>();

            for(int j=1;j<a;j++){
                List<String> lis1=new ArrayList<String>();
                for(int i=0;i<resultList.size();i++){
                    param=resultList.get(i);
                    String b1="value"+j;
                    String b=param.get(b1).toString();
                    lis1.add(b);

                }
                List<String> newList = new  ArrayList<String>();
                for (String cd:lis1) {
                    if(!newList.contains(cd)){
                        newList.add(cd);
                    }
                }
                lis.add(newList);
            }

            Map<String, Object> lis2=new HashMap<String, Object>();
            lis2.put("valueList", lis);
            resultList1.add(lis2);
        }
        return resultList1;
    }

    public static Map<String, Object> kMap(int a[], Map<String, Object> param, Map<String, Object> resultMap, int b,
                                           String str) {
        String val = "";
        if (b == 1) {

            if (a[0] != 1) {
                resultMap.put("spbz", val);
            }
            if (a[1] != 1) {
                a[1] = 1;
                resultMap.put("spbsxlx", val);
            }
            if (a[2] != 1) {
                a[2] = 1;
                resultMap.put("syfdjxh", val);
            }
            if (a[3] != 1) {
                a[3] = 1;
                resultMap.put("spscpbz", val);
            }
            if (a[4] != 1) {
                a[4] = 1;
                resultMap.put("pjsycxqsnf", val);
            }
            if (a[5] != 1) {
                a[5] = 1;
                resultMap.put("pjsycxjznf", val);
            }
            if (a[6] != 1) {
                a[6] = 1;
                resultMap.put("azwz", val);
            }
        }
        if (b == 2) {
            if (a[0] != 1) {

                resultMap.put("prodLine", val);
            }
            for (int i = 1; i <= 5; i++) {
                if (a[i] != 1) {
                    resultMap.put("value" + i + "", val);

                }
            }
        }

        return param;
    }
    public static List<Map<String, Object>> zhuanCd(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("ORDER_MARK").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("ORDER_MARK").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            int a = 0;
            Object [] name=new Object[100];
            Object [] value=new Object[100];
            for (Map<String, Object> param : group) {
                a++;
                resultMap.put("lineNo", param.get("ORDER_MARK"));
                resultMap.put("lineName", param.get("SHOW_LINE_NAME"));
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                name[a]=kString(param.get("SUBLINE_NO"));
                value[a]=kString(param.get("SUBLINE_NAME"));
            }
            List<String> tmp = new ArrayList<String>();
            for(Object str:name){
                if(str!=null && ((String) str).length()!=0){
                    tmp.add((String) str);
                }
            }
            List<String> tmp1 = new ArrayList<String>();
            for(Object str:value){
                if(str!=null && ((String) str).length()!=0){
                    tmp1.add((String) str);
                }
            }
            name = tmp.toArray(new String[0]);
            value = tmp1.toArray(new String[0]);
            resultMap.put("sublineNo",name);
            resultMap.put("sublineName",value);
            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }
    public static List<Map<String, Object>> zhuanMdCd(List<Map<String, Object>> paramsList1) {
        int tempNum = 0;
        List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
        paramsList = paramsList1;
        // 将行数据转变为列数据
        // 将数据分组
        List<List<Map<String, Object>>> groupLists = new ArrayList<List<Map<String, Object>>>();
        List<Map<String, Object>> groupList = null;
        String tempGroupNum = "";
        for (int i = 0; i < paramsList.size(); i++) {
            Map<String, Object> params = paramsList.get(i);
            // 区分组信息
            if (!tempGroupNum.equals(params.get("ORDER_MARK").toString())) {
                if (null != groupList) {
                    groupLists.add(groupList);
                }
                groupList = new ArrayList<Map<String, Object>>();
                tempGroupNum = params.get("ORDER_MARK").toString();
            }
            groupList.add(params);
            if (i == paramsList.size() - 1) {
                groupLists.add(groupList);
            }
        }
        System.out.println(groupLists);

        // 遍历组数据，将组数据转换为行数据
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();

        for (List<Map<String, Object>> group : groupLists) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            List<Map<String, Object>> res=new ArrayList<Map<String,Object>>();
            Object [] name=new Object[100];
            Object [] value=new Object[100];
            for (Map<String, Object> param : group) {
                resultMap.put("lineNo", param.get("ORDER_MARK"));
                resultMap.put("lineName", param.get("SHOW_LINE_NAME"));
                resultMap.put("image", param.get("ICON_NAME"));
                Map<String, Object> names=new HashMap<String, Object>();
                // resultMap.put(param.get("PARA_NAME").toString(),
                // param.get("PARA_VALUE"));
                names.put("name", param.get("SUBLINE_NO"));
                names.put("value", param.get("SUBLINE_NAME"));
                //name[a]=kString(param.get("SUBLINE_NO"));
                //value[a]=kString(param.get("SUBLINE_NAME"));
                res.add(names);
            }
            resultMap.put("names", res);
            resultList.add(resultMap);
        }
        System.out.println(resultList);
        return resultList;
    }
    /*========================================================================*
     *                         Private Methods (私有方法)
     *========================================================================*/
}
